logger.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 1
rs 10
1
var winston = require('winston')
2
var config = require('./')
3
var env = config.env
4
5
const tsFormat = () => '[' + (new Date()).toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1') + ']'
6
7
switch (env) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
8
  case 'development': {
9
    winston.remove(winston.transports.Console)
10
    winston.add(winston.transports.Console, {
11
      level: config.logLevel,
12
      prettyPrint: true,
13
      colorize: 'all',
14
      timestamp: tsFormat,
15
      humanReadableUnhandledException: true
16
    })
17
    break
18
  }
19
20
  case 'production': {
21
    winston.remove(winston.transports.Console)
22
    winston.add(winston.transports.File, {
23
      filename: 'app.log',
24
      level: config.logLevel
25
    })
26
    break
27
  }
28
29
  case 'test': {
30
    winston.remove(winston.transports.Console)
31
    break
32
  }
33
}
34
35
winston.info('ENV=', env)
36
37
module.exports = winston
38